package simple

func finalPrices(prices []int) []int {

	stack := make([]int, 0)
	for i := 0; i < len(prices); i++ {

		for len(stack) != 0 && prices[stack[len(stack)-1]] >= prices[i] {
			pop := stack[len(stack)-1]
			stack = stack[:len(stack)-1]
			prices[pop] = prices[pop] - prices[i]
		}

		stack = append(stack, i)
	}

	return prices
}
